package com.kczd.jinlan.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.kczd.jinlan.R;
import com.kczd.jinlan.adapter.TabLayoutAdapter;
import com.kczd.jinlan.fragment.classfragment.MorenFragment;
import com.kczd.jinlan.fragment.orderfragment.DaipeihuoFragment;
import com.kczd.jinlan.fragment.orderfragment.DaishouhuoFragment;
import com.kczd.jinlan.fragment.orderfragment.DaizhifuFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品筛选页面
 */
public class FoodDetailsActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private TextView mTitle;

    private List<Fragment> list;
    private String[] titles = {"默认", "最热", "价格从低到高", "价格从高到低"};
    private TabLayoutAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_details);

        String titlename=getIntent().getStringExtra("name");
        mTitle= (TextView) findViewById(R.id.id_titlename);
        mTitle.setText(titlename);

        initView();
    }

    private void initView() {
        //实例化
        viewPager = (ViewPager)findViewById(R.id.viewpagers);
        tabLayout = (TabLayout)findViewById(R.id.tablayout_food);



        //页面，数据源
        list = new ArrayList<>();
        list.add(new MorenFragment());
        list.add(new DaizhifuFragment());
        list.add(new DaipeihuoFragment());
        list.add(new DaishouhuoFragment());
        //ViewPager的适配器
        adapter = new TabLayoutAdapter(getSupportFragmentManager(), list, titles);
        viewPager.setAdapter(adapter);
        //绑定
        tabLayout.setupWithViewPager(viewPager);
    }
}
